package com.jereh.cloudmusic.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.jereh.cloudmusic.PlayApplication;
import com.jereh.cloudmusic.constants.Constants;
import com.jereh.cloudmusic.ible.IMusic;

public class PlayReceiver extends BroadcastReceiver {

    private PlayApplication application;
    private IMusic music;


    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.
        application = (PlayApplication) context.getApplicationContext();
        String ctrl_code = intent.getAction();//获取action标记，用户区分点击事件

        music = application.music;//获取全局播放控制对象，该对象已在Activity中初始化
        if (music != null) {
            if ("play".equals(ctrl_code)) {
                music.moveon();
                System.out.println("play");
            } else if ("pause".equals(ctrl_code)) {
                music.pause();
                System.out.println("pause");
            } else if ("next".equals(ctrl_code)) {
                music.nextSong();
                System.out.println("next");
            } else if ("last".equals(ctrl_code)) {
                music.lastSong();
                System.out.println("last");
            }
        }

        if ("cancel".equals(ctrl_code)) {
            application.notiManager.cancel(Constants.PLAY_NOTI_ID);
//            System.exit(0);
        }
    }
}
